package com.lyx.spidemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.lyx.base.IModule1Interface;

import java.util.Iterator;
import java.util.ServiceLoader;

public class HomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                go2Module1Page();
            }
        });
    }

    protected void go2Module1Page() {
        ServiceLoader<IModule1Interface> loader = ServiceLoader.load(IModule1Interface.class);
        Iterator<IModule1Interface> iterator = loader.iterator();
        while (iterator.hasNext()) {
            IModule1Interface next = iterator.next();
            String firstPageClass = next.getModule1FirstPageClass();
            try {
                Class<?> clazz = Class.forName(firstPageClass);
                Intent intent = new Intent(this, clazz);
                startActivity(intent);
            } catch (ClassNotFoundException exception) {
                exception.printStackTrace();
            }
        }
    }

}